#ifndef __XOR_HH__
#define __XOR_HH__

#include <misc/array.h>

inline void double_inplace_xor(double* ret, const double& mask)
{
  int* ret_i_ptr = (int*)ret;
  int* mask_i_ptr = (int*)&mask_i_ptr;
  ret_i_ptr[0] ^= mask_i_ptr[0];
  ret_i_ptr[1] ^= mask_i_ptr[1];
}

inline
template <typename T>
void
inplace_xor(T* v, const T& mask)
{
  *v ^= mask;
}

inline
template <>
void
inplace_xor(double* v, const double& mask)
{
  double_xor(v, mask);
}

// .........................................................

inline 
template <typename T, int N>
void
inplace_xor(array<T, N>* v, 
	    const array<T, N>& mask)
{
  for (int i = 0; i < N; i++) 
    inplace_xor(&v->data[i], mask.data[i]);
}

inline 
template <int N>
void
inplace_xor(array<double, N>* v, 
	    const array<double, N>& mask)
{
  for (int i = 0; i < N; i++) 
    double_xor(&v->data[i], mask.data[i]);
}


#endif
